package views.crm;

import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import java.awt.Font;
import javax.swing.JTextField;

public class CustomerReportView extends JPanel{
	private JTable table;
	private JButton btnApplyFilter;
	private JButton btnSms;
	private JButton btnMail;
	private JTextField textFieldFromDate;
	private JTextField textFieldToDate;
	private JButton btnToDate;
	private JButton btnFromDate;
	private JButton btnPrint;
	
	public CustomerReportView() 
	{
		SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
		
		setSize(870,550);
		
		textFieldFromDate = new JTextField();
		springLayout.putConstraint(SpringLayout.NORTH, textFieldFromDate, 30, SpringLayout.NORTH, this);
		textFieldFromDate.setText("From Date");
		springLayout.putConstraint(SpringLayout.WEST, textFieldFromDate, 30, SpringLayout.WEST, this);
		textFieldFromDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 11));
		textFieldFromDate.setColumns(7);
		add(textFieldFromDate);
		
		btnFromDate = new JButton("Cl1");
		springLayout.putConstraint(SpringLayout.NORTH, btnFromDate, 30, SpringLayout.NORTH,this);
		springLayout.putConstraint(SpringLayout.WEST, btnFromDate, 10, SpringLayout.EAST, textFieldFromDate);
		add(btnFromDate);
		btnFromDate.setActionCommand("Cl1");
		textFieldToDate = new JTextField();
		springLayout.putConstraint(SpringLayout.NORTH, textFieldToDate, 30, SpringLayout.NORTH,this);
		textFieldToDate.setText("To Date");
		springLayout.putConstraint(SpringLayout.WEST, textFieldToDate, 10, SpringLayout.EAST,btnFromDate);
		textFieldToDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 11));
		textFieldToDate.setColumns(7);
		add(textFieldToDate);
		
		btnToDate = new JButton("Cl");
		springLayout.putConstraint(SpringLayout.NORTH, btnToDate, 30, SpringLayout.NORTH,this);
		springLayout.putConstraint(SpringLayout.WEST, btnToDate, 10, SpringLayout.EAST,textFieldToDate);
		add(btnToDate);
		btnToDate.setActionCommand("Cl");
		
		btnApplyFilter = new JButton("APPLY FILTER");
		btnApplyFilter.setFont(new Font("Tahoma", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, btnApplyFilter, 30, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, btnApplyFilter,30, SpringLayout.EAST,btnToDate);
		add(btnApplyFilter);
		btnApplyFilter.setActionCommand("APLLY FILTER");
		
		JSeparator separator = new JSeparator();
		springLayout.putConstraint(SpringLayout.NORTH, separator, 30, SpringLayout.SOUTH,textFieldFromDate);
		springLayout.putConstraint(SpringLayout.WEST, separator, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, separator, -30, SpringLayout.EAST, this);
		add(separator);
		
		JScrollPane scrollPane = new JScrollPane();
		springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 30, SpringLayout.NORTH,separator);
		springLayout.putConstraint(SpringLayout.WEST, scrollPane, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -70, SpringLayout.SOUTH,this);
		springLayout.putConstraint(SpringLayout.EAST, scrollPane, -30, SpringLayout.EAST, this);
		add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"CUSTOMER NAME", "CUSTOMER PHONE", "PURCHASE DATE", "PURCHASE AMOUNT", "SELECT"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false, false, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		table.getColumnModel().getColumn(0).setPreferredWidth(105);
		table.getColumnModel().getColumn(1).setPreferredWidth(113);
		table.getColumnModel().getColumn(2).setPreferredWidth(99);
		table.getColumnModel().getColumn(3).setPreferredWidth(119);
		scrollPane.setViewportView(table);
		
		btnSms = new JButton("Send SMS");
		springLayout.putConstraint(SpringLayout.WEST, btnSms, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.SOUTH, btnSms, -20, SpringLayout.SOUTH, this);
		add(btnSms);
		btnSms.setActionCommand("Send SMS");
		
		btnMail = new JButton("Send Email");
		springLayout.putConstraint(SpringLayout.SOUTH, btnMail, -20, SpringLayout.SOUTH,this);
		springLayout.putConstraint(SpringLayout.WEST, btnMail, 30, SpringLayout.EAST, btnSms);
		add(btnMail);
		btnMail.setActionCommand("Send Email");
		
		btnPrint = new JButton("Print");
		btnPrint.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, btnPrint, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.EAST, btnPrint, -10, SpringLayout.EAST, this);
		add(btnPrint);
		btnPrint.setActionCommand("Print");
	}
	
	
	public JTextField getTextFieldFromDate() {
		return textFieldFromDate;
	}


	public void setTextFieldFromDate(JTextField textFieldFromDate) {
		this.textFieldFromDate = textFieldFromDate;
	}


	public JTextField getTextFieldToDate() {
		return textFieldToDate;
	}


	public void setTextFieldToDate(JTextField textFieldToDate) {
		this.textFieldToDate = textFieldToDate;
	}


	public JButton getBtnToDate() {
		return btnToDate;
	}


	public void setBtnToDate(JButton btnToDate) {
		this.btnToDate = btnToDate;
	}


	public JButton getBtnFromDate() {
		return btnFromDate;
	}


	public void setBtnFromDate(JButton btnFromDate) {
		this.btnFromDate = btnFromDate;
	}


	public JButton getBtnPrint() {
		return btnPrint;
	}


	public void setBtnPrint(JButton btnPrint) {
		this.btnPrint = btnPrint;
	}


	public JTable getTable() {
		return table;
	}
	public void setTable(JTable table) {
		this.table = table;
	}
	
	public JButton getBtnApplyFilter() {
		return btnApplyFilter;
	}
	public void setBtnApplyFilter(JButton btnApplyFilter) {
		this.btnApplyFilter = btnApplyFilter;
	}
	public JButton getBtnSms() {
		return btnSms;
	}
	public void setBtnSms(JButton btnSms) {
		this.btnSms = btnSms;
	}
	public JButton getBtnMail() {
		return btnMail;
	}
	public void setBtnMail(JButton btnMail) {
		this.btnMail = btnMail;
	}
	public void actionlisterner(ActionListener al)
	{
		this.btnApplyFilter.addActionListener(al);
		this.btnFromDate.addActionListener(al);
		this.btnPrint.addActionListener(al);
		this.btnToDate.addActionListener(al);
		this.btnSms.addActionListener(al);
		this.btnMail.addActionListener(al);
		
	}
}
